import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '@/layout'
import appRouter from './modules/app'
import erpRouter from './modules/erp'
import otaRouter from './modules/ota'
import iotRouter from './modules/iot'
import cameraRouter from './modules/camera'
import authRouter from './modules/auth'
import commonRouter from './modules/common'
import extendRouter from './modules/extend'

Vue.use(Router)

export const constantRoutes = [
  ...authRouter,
  ...cameraRouter,
  ...appRouter,
  ...erpRouter,
  ...otaRouter,
  ...iotRouter,
  ...commonRouter,
  ...extendRouter,
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/pages/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/pages/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/pages/error-page/404'),
    hidden: true
  },
  {
    path: '/',
    redirect: '/dashboard',
    component: Layout,
    children: [
      {
        path: '/dashboard',
        component: () => import('@/pages/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'el-icon-guide' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export default router
